package com.example.juc;

import java.util.concurrent.ArrayBlockingQueue;
import java.util.concurrent.Executors;
import java.util.concurrent.ThreadPoolExecutor;
import java.util.concurrent.TimeUnit;

public class ThreadPoolExecuteTest {
    public static void main(String[] args) {
        int CPU = Runtime.getRuntime().availableProcessors();
        System.out.println(CPU);
        ThreadPoolExecutor threadPoolExecutor = new ThreadPoolExecutor(
                2,
                CPU,
                3,
                TimeUnit.SECONDS,
                new ArrayBlockingQueue<>(3),
                Executors.defaultThreadFactory(),
                new ThreadPoolExecutor.CallerRunsPolicy()
        );
        for (int i = 0; i < 9; i++) {
          threadPoolExecutor.execute(()->{
              System.out.println(Thread.currentThread().getName());
          });
        }
    }
}
